package com.graduation.community_manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.community_manager.dao.CmEleWaterDao;
import com.graduation.community_manager.entity.CmEleWaterEntity;
import com.graduation.community_manager.service.CmEleWaterService;
import com.graduation.community_manager.vo.PageCmEleWaterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("cmEleWaterService")
public class CmEleWaterServiceImpl extends ServiceImpl<CmEleWaterDao, CmEleWaterEntity> implements CmEleWaterService {

    @Autowired
    private CmEleWaterDao cmEleWaterDao;

    @Override
    public IPage<CmEleWaterEntity> cmEleWaterPage(PageCmEleWaterVO pageCmEleWaterVO) {
        QueryWrapper<CmEleWaterEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", pageCmEleWaterVO.getUseId());
        wrapper.like("user_name",pageCmEleWaterVO.getUserName()); // 添加用户名的模糊查询条件
        if (pageCmEleWaterVO.getType() == 0) {
            wrapper.between("electricity_pay_time", pageCmEleWaterVO.getStartTime(), pageCmEleWaterVO.getEndTime()); // 添加电费支付时间时间范围的筛选条件
        } else {
            wrapper.between("water_pay_time", pageCmEleWaterVO.getStartTime(), pageCmEleWaterVO.getEndTime()); // 添加水费支付时间时间范围的筛选条件
        }
        IPage<CmEleWaterEntity> page = super.page(Page.of(pageCmEleWaterVO.getCurrent(), pageCmEleWaterVO.getSize()), wrapper);
        return page;
    }

}
